package com.junsi.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.junsi.bean.Record;
import com.junsi.service.RecordService;

import net.sf.json.JSONArray;
/**
 * 记录类型控制器
 * @author lenovo
 *
 */
@Controller
@RequestMapping("/record")
public class RecordController {

	@Autowired
	private RecordService recordService;
	Logger logger=Logger.getRootLogger();

	/**
	 * 新增
	 */
	@RequestMapping("/insert")
	public ModelAndView insert(Record record, HttpServletResponse response) throws Exception {
		recordService.insert(record);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/record//select.action");
		return modelAndView;
	}

	/**
	 * 刪除
	 */
	@RequestMapping("/deletes")
	public ModelAndView deletes(Integer id, HttpServletResponse response) {
		recordService.delete(id);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/record//select.action");
		return modelAndView;
	}

	/**
	 * 更新
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/updata")
	public ModelAndView updata(Record record, HttpServletResponse response) throws Exception {
		recordService.update(record);
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("redirect:/record//select.action");
		return modelAndView;
	}

	/**
	 * 查詢
	 * 
	 * @throws Exception
	 */
	@RequestMapping("/select")
	public ModelAndView select(HttpServletResponse response) throws Exception {
		List<Record> list = recordService.listAll();
		ModelAndView modelAndView=new ModelAndView();
	      modelAndView.addObject("list", list);
	      modelAndView.setViewName("/page/jilu.jsp");
	      return modelAndView;
	}
	
}
